package com.example.common.control;

import android.os.Build;
import android.widget.ImageView;

import androidx.annotation.RequiresApi;
import androidx.databinding.BindingAdapter;

import com.example.common.R;
import com.squareup.picasso.Picasso;

public class MyBindingAdapter {
    @BindingAdapter({"android:iconSrc"})
    public static void setBitmap(ImageView imageView, String url) {
        Picasso.with(imageView.getContext())
                .load(url)
                .placeholder(R.drawable.image_bg_e6e6fa)
                .into(imageView);
    }

    @RequiresApi(api = Build.VERSION_CODES.O_MR1)
    @BindingAdapter({"android:circleIconSrc"})
    public static void setCircleIcon(ImageView imageView, String url) {
        Picasso.with(imageView.getContext())
                .load(url)
                .placeholder(R.drawable.image_bg_e6e6fa)
                .transform(new CircleTransform(imageView.getContext()))
                .into(imageView);
    }

    @RequiresApi(api = Build.VERSION_CODES.O_MR1)
    @BindingAdapter({"android:AvatarCircleIconSrc"})
    public static void setAvatarCircleIcon(ImageView imageView, String url) {
        Picasso.with(imageView.getContext())
                .load(url)
                .placeholder(R.drawable.ic_baseline_account_circle_24)
                .transform(new CircleTransform(imageView.getContext()))
                .into(imageView);
    }
}
